package com.cd.university.config.security.validate.sms;

import com.cd.university.config.security.impl.AbstractValidateCodeProcessor;
import com.cd.university.config.security.validate.ValidateCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.ServletWebRequest;

import java.util.Map;

/**
 * 短信验证码的通用逻辑
 * 1.生成
 * 2.保存（默认保存在session中）
 * 3.发送
 * @author 陈栋
 * @create 2021/9/11 19:37
 */
@Component("smsValidateCodeProcessor")
public class SmsValidateCodeProcessor extends AbstractValidateCodeProcessor<ValidateCode> {

    @Autowired
    private SmsCodeSender smsCodeSender;

    @Override
    public void send(ServletWebRequest request, ValidateCode validateCode) throws Exception {
        Map<String, String[]> parameterMap = request.getRequest().getParameterMap();
        String mobile = request.getRequest().getParameter("mobile");
        smsCodeSender.send(mobile,
                validateCode.getCode(),
                request);
    }
}
